﻿using System.Web.Security;

namespace AspNetMvc.Services.Authentication
{
    // The FormsAuthentication type is sealed and contains static members, so it is difficult to
    // unit test code that calls its members. The interface and helper class below demonstrate
    // how to create an abstract wrapper around such a type in order to make the AccountController
    // code unit testable.

    /// <summary>
    /// Forms authentication service
    /// </summary>
    public class FormsAuthenticationService : IFormsAuthentication
    {
        /// <summary>
        /// Signs user in
        /// </summary>
        /// <param name="userName">Username to sign in</param>
        /// <param name="createPersistentCookie">Creates cookie if true</param>
        public void SignIn(string userName, bool createPersistentCookie)
        {
            FormsAuthentication.SetAuthCookie(userName, createPersistentCookie);
        }

        /// <summary>
        /// Signs current user out
        /// </summary>
        public void SignOut()
        {
            FormsAuthentication.SignOut();
        }
    }
}